<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
    <script type="text/javascript" src="./layui/layui.js"></script>
    <script type="text/javascript" src="./javascript/jquery.min.js"></script>


</head>
<div class="layui-form-item" style="margin-top: 15px;">
    <label class="layui-form-label" style="width: 50px;">周次：</label>
    <div class="layui-input-inline" style="width: 50px;">
        <input type="text" id="week" name="week" value="1" lay-verify="num" placeholder="请输入" autocomplete="off"
            class="layui-input">
    </div>
    <label class="layui-form-label" style="width: 60px;">课程名：</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="text" id="courseName" name="courseName"  lay-verify="required" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>
    <label class="layui-form-label" style="width: 60px;">班级名：</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="text" id="className" name="className" lay-verify="required" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>

    <label class="layui-form-label" style="width: 60px;">教师名：</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="text" id="teacherName" name="teacherName" lay-verify="num" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>
    <label class="layui-form-label" style="width: 60px;">教室名：</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="text" id="roomName" name="roomName" lay-verify="num" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>
    <a class="layui-btn layui-btn" id="findBy" lay-event="addTeaching" style="margin-left: 50px;">查询排课</a>

</div>

<table class="layui-hide" id="demo" name="arr" lay-data="{height: 'full-200', cellMinWidth: 80, page: true, limit:10}"
    lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <!-- <button class="layui-btn layui-btn-sm" lay-event="add">手动添加排课</button>
          <button class="layui-btn layui-btn-sm" lay-event="find">条件查询</button> -->
          <button class="layui-btn layui-btn-sm" lay-event="arr">重新排课</button>

        </div>
      </script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="adjust">调整</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>
<script>


</script>
<script>
    var table;
    $(document).ready(function () {
        var patrn = /^\+?[1-9][0-9]*$/;
        $("#findBy").click(function () {
            var value = $("#week").val();
            if ($("#week").val() == "" || $("#week").val() == null) {
                layer.msg("请输入周次");
            } else if (value = null || value.length == 0 || patrn.exec(value) == null || value > 20 || value < 1) {
                layer.msg("周次只能为1-20非空数字");
                $("#week").val("");
            } else {
                table.reload('demo', {
                    url: "http://127.0.0.1:8088/coursetable/findAllBy?week=" + $("#week").val()
                    + "&teacherName=" + $("#teacherName").val()
                    +"&courseName=" + $("#courseName").val()
                    +"&className=" + $("#className").val()
                    +"&roomName=" + $("#roomName").val()
                })
            }
        });

    });
    layui.use(['table'], function () {
        table = layui.table //表格

        table.render({
            elem: '#demo'

            , url: 'http://127.0.0.1:8088/coursetable/findAll' //数据接口
            , request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            // Integer id, Integer arrId, Integer courseId, Integer classId, Integer roomId, 
            //Integer techerId, Integer semeId, String semeName, Integer timeId, String timeName, 
            //String courseName, String className, String roomName, String techerName, Integer statu, 
            //Integer temporary, String mark
            , title: '班级表'
            , page: true //开启分页
            , toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , cols: [[ //表头
                { type: 'checkbox', fixed: 'left' }
                , { field: 'id', title: 'ID', sort: true, width: 100, fixed: 'left', align: "center" }
                , { field: 'courseName', title: '课程名', width: 180, sort: true, align: "center" }
                , { field: 'className', title: '班级名', width: 150, sort: true, align: "center" }
                , { field: 'techerName', title: '教师名', width: 100, sort: true, align: "center" }
                , { field: 'roomName', title: '教室名', width: 100, sort: true, align: "center" }
                , { field: 'semeName', title: '学期', align: "center" }
                , { field: 'statu', title: '周次', align: "center" }
                , { field: 'timeName', title: '星期', align: "center" }
                , { field: 'timeId', title: '节数', align: "center" }
                , { field: 'temporary', title: '是否是临时', align: "center" }
                , { field: 'mark', title: '备注', align: "center" }
                , { fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo' }
            ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'arr':
                    arr()
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'del') {
                del(data)
            } else if (layEvent === 'adjust') {
                adjust(data)
            } 
        });
    });

    function adjust(data) {
        var url = 'son/adjust.html?id='+data.id;
        console.log(data.id)
        layer.open({
            id: 'adjust',
            type: 2,
            title: "调课",
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['700px', '510px'],
            content: url,
            anim: 1,
        });

    }

    function del(data) {
        layer.confirm('真的删除么', function (index) {
            var url = "http://127.0.0.1:8088/coursetable/del?id=" + data.id;
            $.get(url, function (data, status) {
                console.log(url)
                var ret = JSON.parse(JSON.stringify(data));
                layer.msg(ret.msg);
                if (ret.status == 0) {
                    reload()
                }
            });
        });

    }

    function arr() {
        //询问框
        layer.confirm('确定排课吗？可能导致现有排课信息丢失，请先备份排课信息后确定', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            var index = layer.load(2, { time: 10 * 1000 });
            var url = "http://127.0.0.1:8088/process/arr";
            $.get(url, function (data, status) {
                layer.close(index)
                console.log(url)
                var ret = JSON.parse(JSON.stringify(data));
                if (ret.status == 0) {
                    layer.msg("排课成功，请点击【查看排课】按钮查看排课");
                } else {
                    layer.msg(ret.msg);
                }
                reload();
            });
        }, function () {
        });
    }

    //重新加载table
    function reload() {
        table.reload('demo', {
            url: 'http://127.0.0.1:8088/coursetable/findAll'
        })
    }
</script>

<body>
</body>

</html>